Vue.filter("formatDate", function (value, fmt = "yyyy-MM-dd hh:mm:ss") {
    // 日期对象生成
    let date = null;
    if (value instanceof Date) {
        date = value;
    } else {
        date = new Date(value)
    }
    // 定义获取参数对应正则表达式
    let o = {
        "M+": date.getMonth() + 1, //月份
        "d+": date.getDate(), //日
        "h+": date.getHours(), //小时
        "m+": date.getMinutes(), //分
        "s+": date.getSeconds(), //秒
        "w+": date.getDay(), //星期
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度
        "S": date.getMilliseconds() //毫秒
    };
    // 用正则匹配日期
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (let k in o) {
        if (k === 'w+') {
            if (o[k] === 0) {
                fmt = fmt.replace('w', '周日');
            } else if (o[k] === 1) {
                fmt = fmt.replace('w', '周一');
            } else if (o[k] === 2) {
                fmt = fmt.replace('w', '周二');
            } else if (o[k] === 3) {
                fmt = fmt.replace('w', '周三');
            } else if (o[k] === 4) {
                fmt = fmt.replace('w', '周四');
            } else if (o[k] === 5) {
                fmt = fmt.replace('w', '周五');
            } else if (o[k] === 6) {
                fmt = fmt.replace('w', '周六');
            }
        } else if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}
)

Vue.filter("hideKeyChart",function(value,rule="3:5:3",repStr="*",pos="m"){
    value = value+"";
    rule = rule.split(":");
    let reg = new RegExp(`(\\w{${rule[0]}})(\\w{${rule[1]}})(\\w{${rule[2]}})`);
    let falg = reg.test(value);
    if(!falg){
        return value;
    }
    switch (pos) {
        case "s":
            value = value.replace(RegExp.$1,repStr.repeat(rule[0]))
            break;
        case "m":
            value = value.replace(RegExp.$2,repStr.repeat(rule[1]))
            break;
        case "e":
            value = value.replace(RegExp.$3,repStr.repeat(rule[2]))
            break;
    }
    return value;
})




